package chapter13;

import java.util.Scanner;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;

/**
 * @author : DuJiabao
 * @Date : 2021/2/24 19:56
 * @Project : thinking-in-java
 * @File : null.java
 * @Desc :
 */
public class ThreatAnalyzer {
  static String threatAnalyzer = """
          58.27.82.161@02/10/2005
          204.45.234.40@02/11/2005
          58.27.82.161@02/12/2005
          """;

  public static void main(String[] args) {
    Scanner scanner = new Scanner(threatAnalyzer);
    Pattern p = Pattern.compile("(\\d+[.]\\d+[.]\\d+[.]\\d+)@(\\d{2}[/]\\d{2}/\\d{4})");
    while (scanner.hasNext(p)) {
      scanner.next(p);
      MatchResult match = scanner.match();
      String ip = match.group(1);
      String date = match.group(2);
      System.out.format("Threat on %s from %s\n", date, ip);
    }
  }
}
